package pl.edu.wsinf.lukaszwalczak.emailclient.controller;

import java.util.List;
import javax.inject.Inject;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import pl.edu.wsinf.lukaszwalczak.emailclient.pojo.Contact;
import pl.edu.wsinf.lukaszwalczak.emailclient.repository.ContactRepository;
import pl.edu.wsinf.lukaszwalczak.emailclient.view.ContactListView;

/**
 * Kontroler dla okna z listą kontaktów.
 */
@Component
public class ContactListController {

    @Inject
    private ContactListView view;
    @Inject
    private ContactRepository contactRepository;

    public void showWindow() {
        view.show();
    }

    public void loadList() {
        List<Contact> data = contactRepository.findAll(new Sort("label"));
        view.setContacts(data);
    }

    public void removeContact(Contact contact) {
        contactRepository.delete(contact);
    }
}
